<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2018/11/1
 * Time: 10:25
 */

namespace app\common\model;

use think\Cache;

/**
 * app版本更新信息模型
 * Class AppVersion
 * @package app\common\modelf
 */
class AppVersion extends Base
{
    protected $table = 'wechatadmin.system_app_version';

    /**
     * 获取app版本更新信息,根据app型号和版本,若开启强制更新则返回渠道包号
     * @param array $map
     * @return array|bool|mixed
     */
    public function getVersionData($app_type)
    {
        $data = false;
        if ($this->cache_on >= 1)
        {
            $data = Cache::get('app_version_' . $app_type);
        }

        if ($data === false)
        {
            try
            {
                $data = $this
                    ->field('version,version_name,update_content,force,is_astro_data_from_local,app_update,version_force,version_force_data')
                    ->where(['status' => 1, 'type' => $app_type])
                    ->order('id DESC')->findOrFail()->toArray();
                Cache::set('app_version_' . $app_type, $data, 86400 * 3);

            }
            catch (\Exception $e)
            {
                $data = [];
            }
        }
        return $data;
    }
}
